package com.biter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TradeAdapter extends BaseAdapter {
    private String TAG = "TradeAdapter";
	private Context _mContext = null;
	private List<Map<String,Object>> _dataList = null;
	public TradeAdapter(Context mContext,List<Map<String,Object>> dataList){
		this._mContext = mContext;
		this._dataList = dataList;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return _dataList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return _dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		Map<String,Object> dataMap = _dataList.get(position);
		
		if(convertView==null){
			LayoutInflater mInflater = LayoutInflater.from(_mContext);
		    convertView = mInflater.inflate(R.layout.list_item_trade, null);
		}
		
		TextView tvDate = (TextView)convertView.findViewById(R.id.tvDate);
		TextView tvPrice = (TextView)convertView.findViewById(R.id.tvPrice);
		TextView tvCount = (TextView)convertView.findViewById(R.id.tvCount);
		
		String type = String.valueOf(dataMap.get("type"));
		int font_color = 0;
		if(type.equals("buy")){
			font_color = _mContext.getResources().getColor(R.color.text_blue);
		}else{
			font_color = _mContext.getResources().getColor(R.color.text_red);
		}
		Log.v(TAG, type);
		tvDate.setTextColor(font_color);
		tvDate.setText(String.valueOf(dataMap.get("date")));
		tvPrice.setTextColor(font_color);
		tvPrice.setText(String.valueOf(dataMap.get("price")));
		tvCount.setTextColor(font_color);
		tvCount.setText(String.valueOf(dataMap.get("amount")));
		
		return convertView;
	}

}
